package com.yiwan.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.yiwan.tool.JDBConnection;

public class ToyDao {
	private static Logger log = Logger.getLogger(UserDao.class);
	private JDBConnection connection = null;
	private String sql = null;
	public String toyListTime() {
		String wantall = "";
		connection = new JDBConnection();
		sql = "select name,picture,user.uname,level,toy.describe,toy.date from toy, user where state = 1 and toy.ownerid = user.userid order by date desc";
		ResultSet rs = connection.executeQuery(sql);
		try {
			while (rs.next()) {
				wantall = wantall + rs.getString(1)+","+rs.getString(2)+","+rs.getString(3)+","+rs.getString(4)+","+rs.getString(5)+","+rs.getString(6)+"]";
			}
			log.info(wantall);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return wantall;
	}
	public String toyListTimeDe() {
		String wantall = "";
		connection = new JDBConnection();
		sql = "select name,picture,user.uname,level,toy.describe,toy.date from toy, user where state = 1 and toy.ownerid = user.userid order by date";
		ResultSet rs = connection.executeQuery(sql);
		try {
			while (rs.next()) {
				wantall = wantall + rs.getString(1)+","+rs.getString(2)+","+rs.getString(3)+","+rs.getString(4)+","+rs.getString(5)+","+rs.getString(6)+"]";
			}
			log.info(wantall);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return wantall;
	}
	public String toyListTimeLevel() {
		String wantall = "";
		connection = new JDBConnection();
		sql = "select name,picture,user.uname,level,toy.describe,toy.date from toy, user where state = 1 and toy.ownerid = user.userid order by level desc";
		ResultSet rs = connection.executeQuery(sql);
		try {
			while (rs.next()) {
				wantall = wantall + rs.getString(1)+","+rs.getString(2)+","+rs.getString(3)+","+rs.getString(4)+","+rs.getString(5)+","+rs.getString(6)+"]";
			}
			log.info(wantall);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return wantall;
	}

}
